<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="order_id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input-number v-model="model.orderId" placeholder="请输入order_id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="order_sn" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderSn">
              <a-input v-model="model.orderSn" placeholder="请输入order_sn"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="spu_id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spuId">
              <a-input-number v-model="model.spuId" placeholder="请输入spu_id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="spu_name" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spuName">
              <a-input v-model="model.spuName" placeholder="请输入spu_name"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="spu_pic" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spuPic">
              <a-input v-model="model.spuPic" placeholder="请输入spu_pic"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spuBrand">
              <a-input v-model="model.spuBrand" placeholder="请输入品牌"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品分类id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryId">
              <a-input-number v-model="model.categoryId" placeholder="请输入商品分类id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品sku编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuId">
              <a-input-number v-model="model.skuId" placeholder="请输入商品sku编号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品sku名字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuName">
              <a-input v-model="model.skuName" placeholder="请输入商品sku名字"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品sku图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuPic">
              <a-input v-model="model.skuPic" placeholder="请输入商品sku图片"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品sku价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuPrice">
              <a-input-number v-model="model.skuPrice" placeholder="请输入商品sku价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品购买的数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuQuantity">
              <a-input-number v-model="model.skuQuantity" placeholder="请输入商品购买的数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品销售属性组合（JSON）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuAttrsVals">
              <a-input v-model="model.skuAttrsVals" placeholder="请输入商品销售属性组合（JSON）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品促销分解金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="promotionAmount">
              <a-input-number v-model="model.promotionAmount" placeholder="请输入商品促销分解金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="优惠券优惠分解金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponAmount">
              <a-input-number v-model="model.couponAmount" placeholder="请输入优惠券优惠分解金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="积分优惠分解金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="integrationAmount">
              <a-input-number v-model="model.integrationAmount" placeholder="请输入积分优惠分解金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="该商品经过优惠后的分解金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realAmount">
              <a-input-number v-model="model.realAmount" placeholder="请输入该商品经过优惠后的分解金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="赠送积分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="giftIntegration">
              <a-input-number v-model="model.giftIntegration" placeholder="请输入赠送积分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="赠送成长值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="giftGrowth">
              <a-input-number v-model="model.giftGrowth" placeholder="请输入赠送成长值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'OmsOrderItemForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/order/omsOrderItem/add",
          edit: "/order/omsOrderItem/edit",
          queryById: "/order/omsOrderItem/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>